<?php
if(!class_exists("BaseService")){
	require_once ('BaseService.php');
}

/**
 * @author Virtualidad
 * @version 1.0
 * @created 29-dic-2010 09:57:49 a.m.
 */
class MembershipService extends BaseService {

    public function __construct() {
        //Cambia Esto para que lo setees desde la configuración del plugin
//        parent::__construct("http://api.usbcartagena.edu.co/");
        parent::__construct("http://webservice.usbctg.edu.co/");
//        parent::__construct("http://192.168.80.165/");
    }

    public function getServiceClass() {
        return "Authentication";
    }

    /**
     *
     * @param CodigoEstudiante
     * @param PeriodoAcademico
     *
     * @return ServiceResponse
     */
    function Login($Username, $Password) {
        $response = parent::invokeService("Login", '{"Username":"' . $Username . '","Password":"' . $Password . '"}');

        require_once ('entities/ServiceResponse.php');
        require_once ('entities/User.php');

        /* @var $result ServiceResponse */
        $result = parent::processSingleObjectResponse($response, parent::getMimeType(), "ServiceResponse", array("User" => "User"));
        // TODO: Esto es un apaga incendios, no me juzguen!
        
        
        $responseArray = json_decode($response, true);
        if (isset($responseArray["User"]) && isset($responseArray["User"]["Rol"])) {
            $result->getUser()->setRol($responseArray["User"]["Rol"]);
        }

        return $result;
    }

}

?>